package com.tedu;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * Author：毕龙
 * Date: 2022/9/18 14:00
 * 项目的主类用来启动webserver
 * 该项用来实现一个功能启动Tomcat服务器的核心
 * 了解Http协议以及浏览器与服务端的处理细节
 * 了解SpringMVC的核心的设计与实现
 */
public class BirdBootApplication {
    private ServerSocket serverSocket;
    public BirdBootApplication(){
        try{
            System.out.println("正在启动服务器....");
            serverSocket = new ServerSocket(8088);
            System.out.println("服务器启动完毕!!!");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    //用户请求链接
    public void start(){
        try {
            System.out.println("等待客户端连接.....");
            Socket soc = serverSocket.accept();
            System.out.println("一个客户端连接了");
            //启动一个线程处理该客户端交互
            ClientHandler ch = new ClientHandler(soc);
            Thread thread = new Thread(ch);
            thread.start();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        BirdBootApplication birdBootApplication = new BirdBootApplication();
        birdBootApplication.start();
    }
}
